<template>
	<div>
		<div class="container">
			<div class="handle-box">
				<el-select v-model="query.post" placeholder="岗位" @change="handleSearch(query.name,query.post)"  clearable="" class="handle-select mr10">
					<el-option key="1" label="局长" value="局长" ></el-option>
					<el-option key="2" label="副局长" value="副局长"></el-option>
                    <el-option key="3" label="案件审理岗" value="案件审理岗"></el-option>
                    <el-option key="4" label="专卖监督管理科（股）长" value="专卖监督管理科（股）长" ></el-option>
                    <el-option key="5" label="市场监管岗" value="市场监管岗"></el-option>
                    <el-option key="6" label="执法员" value="执法员"></el-option>
                    <el-option key="7" label="专卖管理所长" value="专卖管理所长" ></el-option>
                    <el-option key="8" label="稽查中队长" value="稽查中队长"></el-option>
                    <el-option key="9" label="卷烟经营企业监管岗" value="卷烟经营企业监管岗"></el-option>
                    <el-option key="10" label="证件管理岗" value="证件管理岗" ></el-option>
                    <el-option key="11" label="情报线索分析岗" value="情报线索分析岗"></el-option>
                    <el-option key="12" label="市场监管岗" value="市场监管岗"></el-option>
                    <el-option key="13" label="情报线索分析岗" value="情报线索分析岗"></el-option>
				</el-select>
				<el-input v-model="query.name" placeholder="姓名" class="handle-input mr10"></el-input>
				<el-button type="primary" :icon="Search" @click="handleSearch(query.name,query.post)">搜索</el-button>
				<el-button type="primary" :icon="Plus" @click="save_create">新增</el-button>
			</div>
			<el-table :data="tableList" border class="table" ref="multipleTable" header-cell-class-name="table-header">
<!--				<el-table-column prop="staff_id" label="ID" width="55" align="center"></el-table-column>-->
				<el-table-column prop="staff_name" label="姓名" align="center"></el-table-column>
        <el-table-column prop="staff_gender" label="性别" width="70" align="center"></el-table-column>
        <el-table-column prop="staff_ethnicity" label="民族" width="100" align="center"></el-table-column>
        <el-table-column prop="staff_post" label="岗位" width="200" align="center"></el-table-column>
        <el-table-column prop="staff_political_status" label="政治面貌" align="center"></el-table-column>
				<el-table-column label="状态" align="center" width="100">
					<template #default="scope">
						<el-tag
							:type="scope.row.staff_authorized === '在编' ? 'success' : scope.row.staff_authorized === '不在编' ? 'danger' : ''"
						>
							{{ scope.row.staff_authorized }}
						</el-tag>
					</template>
				</el-table-column>

				<el-table-column label="操作" width="350" align="center">
					<template #default="scope">
						<el-button text :icon="Edit" @click="handleEdit(scope.$index, scope.row)" >
							修改
						</el-button>
            <el-button text :icon="Edit" @click="start_permiss_edit_Visible(scope.row)" >
              权限修改
            </el-button>
                        <el-button text :icon="Delete" @click="employee_message_delete(scope.$index,scope.row)" class="red" >
                            删除
                        </el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination
					background
					layout="total, prev, pager, next"
					:current-page="query.pageIndex"
					:page-size="query.pageSize"
					:total="pageTotal"
					@current-change="handlePageChange"
				></el-pagination>
			</div>
		</div>

		<!-- 修改弹出框 -->
		<el-dialog title="修改" v-model="editVisible" width="30%">
			<el-form label-width="150px">
                <el-form-item label="登录账号">
                    <el-input v-model="user_data.staff_account_no"></el-input>
                </el-form-item>
                <el-form-item label="登录密码">
                    <el-input v-model="user_data.staff_account_pwd"></el-input>
                </el-form-item>
				<el-form-item label="姓名">
					<el-input v-model="user_data.staff_name"></el-input>
				</el-form-item>
				<el-form-item label="性别">
          <el-select v-model=" user_data.staff_gender" placeholder="性别" class="handle-select mr10">
            <el-option key="1" label="男" value="男" ></el-option>
            <el-option key="2" label="女" value="女"></el-option>
          </el-select>
				</el-form-item>
        <el-form-item label="出生日期">
            <el-date-picker v-model="user_data.staff_birthday"  type="datetime" placeholder="选择出生日期" value-format="YYYY-MM-DD HH:mm:ss">
            </el-date-picker>
        </el-form-item>
        <el-form-item label="民族">
            <el-select v-model="user_data.staff_ethnicity" placeholder="请选择民族" class="handle-select mr10">
                <el-option key="1" label="汉族" value="汉族"></el-option>
                <el-option key="2" label="蒙古族" value="蒙古族"></el-option>
                <el-option key="3" label="回族" value="回族"></el-option>
                <el-option key="4" label="藏族" value="藏族"></el-option>
                <el-option key="5" label="维吾尔族" value="维吾尔族"></el-option>
                <el-option key="6" label="苗族" value="苗族"></el-option>
                <el-option key="7" label="彝族" value="彝族"></el-option>
                <el-option key="8" label="壮族" value="壮族"></el-option>
                <el-option key="9" label="布依族" value="布依族"></el-option>
                <el-option key="10" label="朝鲜族" value="朝鲜族"></el-option>
                <el-option key="11" label="满族" value="满族"></el-option>
                <el-option key="12" label="侗族" value="侗族"></el-option>
                <el-option key="13" label="瑶族" value="瑶族"></el-option>
                <el-option key="14" label="白族" value="白族"></el-option>
                <el-option key="15" label="土家族" value="土家族"></el-option>
                <el-option key="16" label="哈尼族" value="哈尼族"></el-option>
                <el-option key="17" label="哈萨克族" value="哈萨克族"></el-option>
                <el-option key="18" label="傣族" value="傣族"></el-option>
                <el-option key="19" label="黎族" value="黎族"></el-option>
                <el-option key="20" label="傈僳族" value="傈僳族"></el-option>
                <el-option key="21" label="佤族" value="佤族"></el-option>
                <el-option key="22" label="畲族" value="畲族"></el-option>
                <el-option key="23" label="高山族" value="高山族"></el-option>
                <el-option key="24" label="拉祜族" value="拉祜族"></el-option>
                <el-option key="25" label="水族" value="水族"></el-option>
                <el-option key="26" label="东乡族" value="东乡族"></el-option>
                <el-option key="27" label="纳西族" value="纳西族"></el-option>
                <el-option key="28" label="景颇族" value="景颇族"></el-option>
                <el-option key="29" label="柯尔克孜族" value="柯尔克孜族"></el-option>
                <el-option key="30" label="土族" value="土族"></el-option>
                <el-option key="31" label="达斡尔族" value="达斡尔族"></el-option>
                <el-option key="32" label="仫佬族" value="仫佬族"></el-option>
                <el-option key="33" label="羌族" value="羌族"></el-option>
                <el-option key="34" label="布朗族" value="布朗族"></el-option>
                <el-option key="35" label="撒拉族" value="撒拉族"></el-option>
                <el-option key="36" label="毛南族" value="毛南族"></el-option>
                <el-option key="37" label="仡佬族" value="仡佬族"></el-option>
                <el-option key="38" label="锡伯族" value="锡伯族"></el-option>
                <el-option key="39" label="阿昌族" value="阿昌族"></el-option>
                <el-option key="40" label="普米族" value="普米族"></el-option>
                <el-option key="41" label="塔吉克族" value="塔吉克族"></el-option>
                <el-option key="42" label="怒族" value="怒族"></el-option>
                <el-option key="43" label="乌孜别克族" value="乌孜别克族"></el-option>
                <el-option key="44" label="俄罗斯族" value="俄罗斯族"></el-option>
                <el-option key="45" label="鄂温克族" value="鄂温克族"></el-option>
                <el-option key="46" label="德昂族" value="德昂族"></el-option>
                <el-option key="47" label="保安族" value="保安族"></el-option>
                <el-option key="48" label="裕固族" value="裕固族"></el-option>
                <el-option key="49" label="京族" value="京族"></el-option>
                <el-option key="50" label="塔塔尔族" value="塔塔尔族"></el-option>
                <el-option key="51" label="独龙族" value="独龙族"></el-option>
                <el-option key="52" label="鄂伦春族" value="鄂伦春族"></el-option>
                <el-option key="53" label="赫哲族" value="赫哲族"></el-option>
                <el-option key="54" label="门巴族" value="门巴族"></el-option>
                <el-option key="55" label="珞巴族" value="珞巴族"></el-option>
                <el-option key="56" label="基诺族" value="基诺族"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="学历">
            <el-select v-model="user_data.staff_edu_bg" placeholder="请选择" class="handle-select mr10">
                <el-option key="1" label="博士研究生" value="博士研究生" ></el-option>
                <el-option key="2" label="硕士研究生" value="硕士研究生"></el-option>
                <el-option key="3" label="中央党校研究生" value="中央党校研究生" ></el-option>
                <el-option key="4" label="省(市、区)委党校研究生" value="省(市、区)委党校研究生"></el-option>
                <el-option key="5" label="大学本科" value="大学本科" ></el-option>
                <el-option key="6" label="中央党校大学" value="中央党校大学"></el-option>
                <el-option key="7" label="大专" value="大专" ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="user_data.staff_email"></el-input>
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input v-model="user_data.field_staff_identity_card"></el-input>
        </el-form-item>
        <el-form-item label="籍贯">
          <el-input v-model="user_data.staff_hometown"></el-input>
        </el-form-item>
        <el-form-item label="职级">
          <el-input v-model="user_data.staff_degree"></el-input>
        </el-form-item>
        <el-form-item label="政治面貌">
            <el-select v-model="user_data.staff_political_status" placeholder="请选择" class="handle-select mr10">
                <el-option key="1" label="群众" value="群众" ></el-option>
                <el-option key="2" label="共青团员" value="共青团员"></el-option>
                <el-option key="3" label="中共党员" value="中共党员" ></el-option>
                <el-option key="4" label="中共预备党员" value="中共预备党员"></el-option>
                <el-option key="5" label="民革党员" value="民革党员" ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="岗位">
            <el-input v-model="user_data.staff_post"></el-input>
        </el-form-item>
        <el-form-item label="工作单位名称">
            <el-select v-model="user_data.work_unit_name" placeholder="请选择" class="handle-select mr10">
                <el-option key="1" label="局领导" value="局领导" ></el-option>
                <el-option key="2" label="专卖监督管理科（股）" value="专卖监督管理科（股）"></el-option>
                <el-option key="3" label="甘蔗专管所" value="甘蔗专管所" ></el-option>
                <el-option key="4" label="青口专管所" value="青口专管所"></el-option>
                <el-option key="5" label="上街专管所" value="上街专管所" ></el-option>
                <el-option key="6" label="专卖稽查中队" value="专卖稽查中队" ></el-option>
                <el-option key="7" label="内部专卖管理监督派驻工作组" value="内部专卖管理监督派驻工作组"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="参加工作时间">
            <el-date-picker v-model="user_data.staff_starting_time"  type="datetime" placeholder="选择参加工作时间" value-format="YYYY-MM-DD HH:mm:ss">
            </el-date-picker>
        </el-form-item>
        <el-form-item label="编制">
          <el-select v-model="user_data.staff_authorized" placeholder="请选择" class="handle-select mr10">
            <el-option key="1" label="在编" value="在编" ></el-option>
            <el-option key="2" label="不在编" value="不在编"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="user_data.staff_phone"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="user_data.staff_tel"></el-input>
        </el-form-item>
        <el-form-item label="签名">
          <el-input v-model="user_data.staff_e_sign"></el-input>
        </el-form-item>
        <el-form-item label="微号码">
          <el-input v-model="user_data.staff_small_number"></el-input>
        </el-form-item>
        <el-form-item label="烟草专卖执法证号">
          <el-input v-model="user_data.staff_license_no"></el-input>
        </el-form-item>
        <el-form-item label="当前聘任等级">
          <el-input v-model="user_data.staff_now_work_degree"></el-input>
        </el-form-item>
        <el-form-item label="当前鉴定等级">
          <el-input v-model="user_data.staff_now_evaluate_degree"></el-input>
        </el-form-item>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="editVisible = false">取 消</el-button>
					<el-button type="primary" @click="saveEdit">确 定</el-button>
				</span>
			</template>
		</el-dialog>

    <!-- 创建新用户弹出框 -->
    <el-dialog title="创建新用户" v-model="user_create_Visible" width="38%">
      <el-form label-width="150px">
          <el-form-item label="登录账号">
              <el-input v-model="create.staff_account_no"></el-input>
          </el-form-item>
          <el-form-item label="登录密码">
              <el-input v-model="create.staff_account_pwd"></el-input>
          </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="create.staff_name"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="create.staff_gender" placeholder="性别" class="handle-select mr10">
            <el-option key="1" label="男" value="男" ></el-option>
            <el-option key="2" label="女" value="女"></el-option>
          </el-select>
        </el-form-item>
          <el-form-item label="出生日期">

              <el-date-picker v-model="create.staff_birthday"  type="datetime" placeholder="选择出生日期" value-format="YYYY-MM-DD HH:mm:ss">
              </el-date-picker>
          </el-form-item>

        <el-form-item label="民族">
          <el-select v-model="create.staff_ethnicity" placeholder="请选择民族" class="handle-select mr10">
              <el-option key="1" label="汉族" value="汉族"></el-option>
              <el-option key="2" label="蒙古族" value="蒙古族"></el-option>
              <el-option key="3" label="回族" value="回族"></el-option>
              <el-option key="4" label="藏族" value="藏族"></el-option>
              <el-option key="5" label="维吾尔族" value="维吾尔族"></el-option>
              <el-option key="6" label="苗族" value="苗族"></el-option>
              <el-option key="7" label="彝族" value="彝族"></el-option>
              <el-option key="8" label="壮族" value="壮族"></el-option>
              <el-option key="9" label="布依族" value="布依族"></el-option>
              <el-option key="10" label="朝鲜族" value="朝鲜族"></el-option>
              <el-option key="11" label="满族" value="满族"></el-option>
              <el-option key="12" label="侗族" value="侗族"></el-option>
              <el-option key="13" label="瑶族" value="瑶族"></el-option>
              <el-option key="14" label="白族" value="白族"></el-option>
              <el-option key="15" label="土家族" value="土家族"></el-option>
              <el-option key="16" label="哈尼族" value="哈尼族"></el-option>
              <el-option key="17" label="哈萨克族" value="哈萨克族"></el-option>
              <el-option key="18" label="傣族" value="傣族"></el-option>
              <el-option key="19" label="黎族" value="黎族"></el-option>
              <el-option key="20" label="傈僳族" value="傈僳族"></el-option>
              <el-option key="21" label="佤族" value="佤族"></el-option>
              <el-option key="22" label="畲族" value="畲族"></el-option>
              <el-option key="23" label="高山族" value="高山族"></el-option>
              <el-option key="24" label="拉祜族" value="拉祜族"></el-option>
              <el-option key="25" label="水族" value="水族"></el-option>
              <el-option key="26" label="东乡族" value="东乡族"></el-option>
              <el-option key="27" label="纳西族" value="纳西族"></el-option>
              <el-option key="28" label="景颇族" value="景颇族"></el-option>
              <el-option key="29" label="柯尔克孜族" value="柯尔克孜族"></el-option>
              <el-option key="30" label="土族" value="土族"></el-option>
              <el-option key="31" label="达斡尔族" value="达斡尔族"></el-option>
              <el-option key="32" label="仫佬族" value="仫佬族"></el-option>
              <el-option key="33" label="羌族" value="羌族"></el-option>
              <el-option key="34" label="布朗族" value="布朗族"></el-option>
              <el-option key="35" label="撒拉族" value="撒拉族"></el-option>
              <el-option key="36" label="毛南族" value="毛南族"></el-option>
              <el-option key="37" label="仡佬族" value="仡佬族"></el-option>
              <el-option key="38" label="锡伯族" value="锡伯族"></el-option>
              <el-option key="39" label="阿昌族" value="阿昌族"></el-option>
              <el-option key="40" label="普米族" value="普米族"></el-option>
              <el-option key="41" label="塔吉克族" value="塔吉克族"></el-option>
              <el-option key="42" label="怒族" value="怒族"></el-option>
              <el-option key="43" label="乌孜别克族" value="乌孜别克族"></el-option>
              <el-option key="44" label="俄罗斯族" value="俄罗斯族"></el-option>
              <el-option key="45" label="鄂温克族" value="鄂温克族"></el-option>
              <el-option key="46" label="德昂族" value="德昂族"></el-option>
              <el-option key="47" label="保安族" value="保安族"></el-option>
              <el-option key="48" label="裕固族" value="裕固族"></el-option>
              <el-option key="49" label="京族" value="京族"></el-option>
              <el-option key="50" label="塔塔尔族" value="塔塔尔族"></el-option>
              <el-option key="51" label="独龙族" value="独龙族"></el-option>
              <el-option key="52" label="鄂伦春族" value="鄂伦春族"></el-option>
              <el-option key="53" label="赫哲族" value="赫哲族"></el-option>
              <el-option key="54" label="门巴族" value="门巴族"></el-option>
              <el-option key="55" label="珞巴族" value="珞巴族"></el-option>
              <el-option key="56" label="基诺族" value="基诺族"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学历">
          <el-select v-model="create.staff_edu_bg" placeholder="请选择" class="handle-select mr10">
              <el-option key="1" label="博士研究生" value="博士研究生" ></el-option>
              <el-option key="2" label="硕士研究生" value="硕士研究生"></el-option>
              <el-option key="3" label="中央党校研究生" value="中央党校研究生" ></el-option>
              <el-option key="4" label="省(市、区)委党校研究生" value="省(市、区)委党校研究生"></el-option>
              <el-option key="5" label="大学本科" value="大学本科" ></el-option>
              <el-option key="6" label="中央党校大学" value="中央党校大学"></el-option>
              <el-option key="7" label="大专" value="大专" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="create.staff_email"></el-input>
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input v-model="create.field_staff_identity_card"></el-input>
        </el-form-item>
        <el-form-item label="籍贯">
          <el-input v-model="create.staff_hometown"></el-input>
        </el-form-item>
        <el-form-item label="职级">
          <el-input v-model="create.staff_degree"></el-input>
        </el-form-item>
        <el-form-item label="政治面貌">
          <el-select v-model="create.staff_political_status" placeholder="请选择" class="handle-select mr10">
              <el-option key="1" label="群众" value="群众" ></el-option>
              <el-option key="2" label="共青团员" value="共青团员"></el-option>
              <el-option key="3" label="中共党员" value="中共党员" ></el-option>
              <el-option key="4" label="中共预备党员" value="中共预备党员"></el-option>
              <el-option key="5" label="民革党员" value="民革党员" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岗位">
            <el-input v-model="create.staff_post"></el-input>
        </el-form-item>
          <el-form-item label="工作单位名称">
              <el-select v-model="create.work_unit_name" placeholder="请选择" class="handle-select mr10">
                  <el-option key="1" label="局领导" value="局领导" ></el-option>
                  <el-option key="2" label="专卖监督管理科（股）" value="专卖监督管理科（股）"></el-option>
                  <el-option key="3" label="甘蔗专管所" value="甘蔗专管所" ></el-option>
                  <el-option key="4" label="青口专管所" value="青口专管所"></el-option>
                  <el-option key="5" label="上街专管所" value="上街专管所" ></el-option>
                  <el-option key="6" label="专卖稽查中队" value="专卖稽查中队" ></el-option>
                  <el-option key="7" label="内部专卖管理监督派驻工作组" value="内部专卖管理监督派驻工作组"></el-option>
              </el-select>
          </el-form-item>
        <el-form-item label="参加工作时间">

            <el-date-picker v-model="create.staff_starting_time"  type="datetime" placeholder="选择参加工作时间" value-format="YYYY-MM-DD HH:mm:ss">
            </el-date-picker>
        </el-form-item>
        <el-form-item label="编制">
          <el-select v-model="create.staff_authorized" placeholder="请选择" class="handle-select mr10">
            <el-option key="1" label="在编" value="在编" ></el-option>
            <el-option key="2" label="不在编" value="不在编"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="create.staff_phone"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="create.staff_tel"></el-input>
        </el-form-item>
<!--        <el-form-item label="签名">-->
<!--          <el-input v-model="create.staff_e_sign"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="微号码">
          <el-input v-model="create.staff_small_number"></el-input>
        </el-form-item>
        <el-form-item label="烟草专卖执法证号">
          <el-input v-model="create.staff_license_no"></el-input>
        </el-form-item>
        <el-form-item label="当前聘任等级">
          <el-input v-model="create.staff_now_work_degree"></el-input>
        </el-form-item>
        <el-form-item label="当前鉴定等级">
          <el-input v-model="create.staff_now_evaluate_degree"></el-input>
        </el-form-item>

      </el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="user_create_Visible = false">取 消</el-button>
					<el-button type="primary" @click="save_create_Edit">确 定</el-button>
				</span>
      </template>
    </el-dialog>

    <el-dialog title="权限修改" v-model="permiss_edit_Visible" width="40%">
      <div class="mgb20 tree-wrapper">
        <el-tree
            ref="tree"
            :data="permisss_data"
            node-key="id"
            default-expand-all
            show-checkbox
            :default-checked-keys="checkedKeys"
        />
      </div>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="permiss_edit_Visible = false">取 消</el-button>
					<el-button type="primary"  @click="save_permiss_Edit">确 定</el-button>
				</span>
      </template>
    </el-dialog>


	</div>
</template>

<script setup lang="ts" name="table_employee">
import { ref, reactive } from 'vue';
import {ElMessage, ElMessageBox, ElTree} from 'element-plus';
import { Delete, Edit, Search, Plus } from '@element-plus/icons-vue';
import {
    employee_delete,
    featch_permiss_data,
    featch_user_permiss_data,
    fetchData_user,
    fetchData_user_Create,
    fetchData_user_Edit, legal_clause_delete, staff_permiss_data_create
} from '../api/index';

interface TableItem {
    id: number;
    name: string;
    idcard: string;
    state: string;
    post:string;
    sex:string;
}

interface Tree {
  id: string;
  label: string;
  children?: Tree[];
}

const permisss_data = ref<Tree[]>([])


const checkedKeys = ref<string[]>([]);

const start_permiss_edit_Visible = (row:any) =>{
  checkedKeys.value = []
  featch_permiss_data().then(res=>{
    permisss_data.value = res.data.data
  })
  featch_user_permiss_data(row.staff_account_no).then(res=>{
    checkedKeys.value = res.data.data
  })
  permiss_edit_Visible.value = true
  create.staff_account_no = row.staff_account_no
}
const tree = ref<InstanceType<typeof ElTree>>();

const save_permiss_Edit =()=>{
  var len = permisss_data.value.length
  var data =tree.value!.getCheckedKeys(false)
  var permiss=""
  for (let i=1; i<=len; i++){
    if (data.indexOf(i) !== -1){
      permiss = permiss + "1"
    }
    else {
      permiss = permiss + "0"
    }
  }
  staff_permiss_data_create(create.staff_account_no,permiss).then(res=>{
    if (res.data.message === "success"){
      ElMessage.success('修改成功');
      getData();
      permiss_edit_Visible.value = false;

    }else {
      ElMessageBox.confirm('修改失败', '提示', {
        type: 'warning'
      })
    }

  })
}

// import {  inject } from 'vue-demi'
//
// const reload = inject('reload')


//人员信息删除
const employee_message_delete = (index:number,row:any) =>{
    // 二次确认删除
    ElMessageBox.confirm('确定要删除吗？', '提示', {
        type: 'warning'
    }).then(() => {
        employee_delete(row.staff_id).then(res=>{
            if (res.data.message === "success"){
                tableData.value.splice(index, 1);
                ElMessage.success('删除成功');
                // reload();
                getData();
            }else {
                ElMessageBox.confirm('删除失败', '提示', {
                    type: 'warning'
                })
            }
        })
    })
        .catch(() => {});
}


const query = reactive({
	post: '',
	name: '',
	pageIndex: 1,
	pageSize: 10
});

const create = reactive({
  staff_name:'',
  staff_gender:'',
  staff_birthday:'',
  staff_ethnicity:'',
  staff_edu_bg:'',
  staff_email:'',
  field_staff_identity_card:'',
  staff_hometown:'',
  staff_degree:'',
  staff_political_status:'',
  staff_post:'',
  staff_account_no:'',
  staff_account_pwd:'',
  staff_starting_time:'',
  staff_authorized:'',
  staff_phone:'',
  staff_tel:'',
  staff_e_sign:'',
  staff_small_number:'',
  staff_license_no:'',
  staff_now_work_degree:'',
  staff_now_evaluate_degree:'',
    work_unit_name:'',
});

// 表格编辑时弹窗和保存
const user_create_Visible = ref(false);
const permiss_edit_Visible = ref(false);
const save_create = () =>{
  user_create_Visible.value = true
}

const save_create_Edit = () =>{
    if(create.staff_account_no.length==0){
        alert("请输入账号")
    }else if(create.staff_account_pwd.length==0){
        alert("请输入密码")
    }else if(create.staff_name.length==0){
        alert("请输入姓名")
    }else if(create.staff_gender.length==0){
        alert("请选择性别")
    }else if(create.staff_birthday.length==0){
        alert("请选择出生日期")
    }else if(create.staff_ethnicity.length==0){
        alert("请选择民族")
    }else if(create.staff_edu_bg.length==0){
        alert("请选择学历")
    }else if(create.field_staff_identity_card.length==0){
        alert("请输入身份证号")
    }else if(create.staff_hometown.length==0){
        alert("请输入籍贯")
    }else if(create.staff_degree.length==0){
        alert("请输入职级")
    }else if(create.staff_political_status.length==0){
        alert("请选择政治面貌")
    }else if(create.staff_post.length==0){
        alert("请选择岗位")
    }else if(create.work_unit_name.length==0){
        alert("请选择工作单位")
    }else if(create.staff_starting_time.length==0){
        alert("请选择参加工作时间")
    }else if(create.staff_authorized.length==0){
        alert("请选择编制情况")
    }else if(create.staff_phone.length==0){
        alert("请输入手机号")
    }else if(create.staff_license_no.length==0){
        alert("请输入烟草专卖执法检查证号")
    }else if(create.staff_now_work_degree.length==0){
        alert("请输入当前聘任等级")
    }else if(create.staff_now_evaluate_degree.length==0){
        alert("请输入当前鉴定等级")
    }else{
        fetchData_user_Create(
            create.staff_account_no,
            create.staff_account_pwd,
            create.staff_name,
            create.staff_gender,
            create.staff_birthday,
            create.staff_ethnicity,
            create.staff_edu_bg,
            create.staff_email,
            create.field_staff_identity_card,
            create.staff_hometown,
            create.staff_degree,
            create.staff_political_status,
            create.staff_post,
            create.work_unit_name,
            create.staff_starting_time,
            create.staff_authorized,
            create.staff_phone,
            create.staff_tel,
            create.staff_e_sign,
            create.staff_small_number,
            create.staff_license_no,
            create.staff_now_work_degree,
            create.staff_now_evaluate_degree).then(res => {
            if (res.data.message === "success"){
                ElMessage.success('修改成功');
                getData()
            }else if(res.data.message === "AccountNoExist"){
                ElMessageBox.confirm('账户已存在', '提示', {
                    type: 'warning'
                })
            }else if(res.data.message ==="LicenseNoExist"){
                ElMessageBox.confirm('烟草专卖执法检查证号已有用户使用，请更换', '提示', {
                    type: 'warning'
                })
            }else{
                ElMessageBox.confirm('添加失败', '提示', {
                    type: 'warning'
                })
            }
        });
        user_create_Visible.value = false;
    }


}

const tableData = ref<TableItem[]>([]);
const tableList = ref<TableItem[]>([]); // 用于存放分页数据的列表
const pageTotal = ref(0);
// 获取表格数据
const getData = (name:string,post:string) => {
  fetchData_user(name,post).then(res => {
    tableList.value = [];
		tableData.value = res.data.data;
		pageTotal.value = res.data.data.length || 50;
    // 根据页码确定下标位置
    const index: number = query.pageIndex * query.pageSize - query.pageSize;
    for (let i = index; i < index + query.pageSize; i++) {
      // 防止数组下标越界
      if (i <= tableData.value.length - 1) {
        tableList.value.push(tableData.value[i])
      } else {
        // 越界就不再循环
        break;
      }
    }
	});
};
getData();

// 查询操作
const handleSearch = (name:string='',post:string='') => {
	query.pageIndex = 1;
	getData(name,post);
};
// 分页导航
const handlePageChange = (val: number) => {
	query.pageIndex = val;
	getData();
};

// 删除操作
const handleDelete = (index: number) => {
	// 二次确认删除
	ElMessageBox.confirm('确定要删除吗？', '提示', {
		type: 'warning'
	})
		.then(() => {
			ElMessage.success('删除成功');
            getData();
			tableData.value.splice(index, 1);
		})
		.catch(() => {});
};

// 表格编辑时弹窗和保存
const editVisible = ref(false);
let user_data = reactive({
  staff_id:0,
  staff_name:'',
  staff_gender:'',
  staff_birthday:'',
  staff_ethnicity:'',
  staff_edu_bg:'',
  staff_email:'',
  field_staff_identity_card:'',
  staff_hometown:'',
  staff_degree:'',
  staff_political_status:'',
  staff_post:'',
    work_unit_name:'',
  staff_account_no:'',
  staff_account_pwd:'',
  staff_starting_time:'',
  staff_authorized:'',
  staff_phone:'',
  staff_tel:'',
  staff_e_sign:'',
  staff_small_number:'',
  staff_license_no:'',
  staff_now_work_degree:'',
  staff_now_evaluate_degree:'',
  flag:'',
});
let idx: number = -1;
const handleEdit = (index: number, row: any) => {
  user_data.staff_id = row.staff_id;
  user_data.staff_name = row.staff_name;
  user_data.staff_gender=row.staff_gender;
  user_data.staff_birthday=row.staff_birthday;
  user_data.staff_ethnicity=row.staff_ethnicity;
  user_data.staff_edu_bg=row.staff_edu_bg;
  user_data.staff_email=row.staff_email;
  user_data.field_staff_identity_card=row.field_staff_identity_card;
  user_data.staff_hometown=row.staff_hometown;
  user_data.staff_degree=row.staff_degree;
  user_data.staff_political_status=row.staff_political_status;
  user_data.staff_post=row.staff_post;
  user_data.work_unit_name=row.work_unit_name;
  user_data.staff_account_no=row.staff_account_no;
  user_data.staff_account_pwd=row.staff_account_pwd;
  user_data.staff_starting_time=row.staff_starting_time;
  user_data.staff_authorized=row.staff_authorized;
  user_data.staff_phone=row.staff_phone;
  user_data.staff_tel=row.staff_tel;
  user_data.staff_e_sign=row.staff_e_sign;
  user_data.staff_small_number=row.staff_small_number;
  user_data.staff_license_no=row.staff_license_no;
  user_data.staff_now_work_degree=row.staff_now_work_degree;
  user_data.staff_now_evaluate_degree=row.staff_now_evaluate_degree;
  editVisible.value=true;
};
const saveEdit = () => {
    if(user_data.staff_account_no.length==0){
        alert("请输入账号")
    }else if(user_data.staff_account_pwd.length==0){
        alert("请输入密码")
    }else if(user_data.staff_name.length==0){
        alert("请输入姓名")
    }else if(user_data.staff_gender.length==0){
        alert("请选择性别")
    }else if(user_data.staff_birthday.length==0){
        alert("请选择出生日期")
    }else if(user_data.staff_ethnicity.length==0){
        alert("请选择民族")
    }else if(user_data.staff_edu_bg.length==0){
        alert("请选择学历")
    }else if(user_data.field_staff_identity_card.length==0){
        alert("请输入身份证号")
    }else if(user_data.staff_hometown.length==0){
        alert("请输入籍贯")
    }else if(user_data.staff_degree.length==0){
        alert("请输入职级")
    }else if(user_data.staff_political_status.length==0){
        alert("请选择政治面貌")
    }else if(user_data.staff_post.length==0){
        alert("请选择岗位")
    }else if(user_data.work_unit_name.length==0){
        alert("请选择工作单位")
    }else if(user_data.staff_starting_time.length==0){
        alert("请选择参加工作时间")
    }else if(user_data.staff_authorized.length==0){
        alert("请选择编制情况")
    }else if(user_data.staff_phone.length==0){
        alert("请输入手机号")
    }else if(user_data.staff_license_no.length==0){
        alert("请输入烟草专卖执法检查证号")
    }else if(user_data.staff_now_work_degree.length==0){
        alert("请输入当前聘任等级")
    }else if(user_data.staff_now_evaluate_degree.length==0){
        alert("请输入当前鉴定等级")
    }else{
        fetchData_user_Edit(
            user_data.staff_account_no,
            user_data.staff_account_pwd,
            user_data.staff_id,
            user_data.staff_name,
            user_data.staff_gender,
            user_data.staff_birthday,
            user_data.staff_ethnicity,
            user_data.staff_edu_bg,
            user_data.staff_email,
            user_data.field_staff_identity_card,
            user_data.staff_hometown,
            user_data.staff_degree,
            user_data.staff_political_status,
            user_data.staff_post,
            user_data.work_unit_name,
            user_data.staff_starting_time,
            user_data.staff_authorized,
            user_data.staff_phone,
            user_data.staff_tel,
            user_data.staff_e_sign,
            user_data.staff_small_number,
            user_data.staff_license_no,
            user_data.staff_now_work_degree,
            user_data.staff_now_evaluate_degree).then(res => {
            if (res.data.message === "success"){
                ElMessage.success('修改成功');
                getData();
            }else if(res.data.message === "AccountNoExist"){
                ElMessageBox.confirm('账号已存在,请重新修改账号', '提示', {
                    type: 'warning'
                })
            }else if(res.data.message ==="LicenseNoExist"){
                ElMessageBox.confirm('烟草专卖执法检查证号已有用户使用，请更换', '提示', {
                    type: 'warning'
                })
            } else {
                ElMessageBox.confirm('修改失败', '提示', {
                    type: 'warning'
                })
            }});
        editVisible.value = false;
    }


};
</script>

<style scoped>
.handle-box {
	margin-bottom: 20px;

}
.handle-box button{
    background-color: #00a854;
}

.handle-select {
	width: 120px;
}

.handle-input {
	width: 300px;
}
.table {
	width: 100%;
	font-size: 14px;
}
.red {
	color: #ff0000;
}
.mr10 {
	margin-right: 10px;
}
.table-td-thumb {
	display: block;
	margin: auto;
	width: 40px;
	height: 40px;
}
.dialog-footer button{
    background-color: #00a854;
    color:white;
}

</style>
